<%@ page isELIgnored="false" language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>


<script type="text/javascript">
    $(function(){
        /*加载登录对话框设置加载时隐藏属性  */
        $("#addGuruDialog").dialog({
            title: "添加框",
            width: 600,
            height: 300,
            closed: true,
            buttons:[{
                text:"添加",
                handler:function(){
                    doadd();
                },
            }],
        });
        /*加载修改对话框设置加载时隐藏属性---------------END  */
        $("#updateGuruDialog").dialog({
            title: "修改框",
            width: 600,
            height: 500,
            closed: true,
            buttons:[{
                text:"修改",
                handler:function(){
                    update();
                },
            }],
        });
        /*加载修改对话框设置加载时隐藏属性---------------END  */



       $("#allGuru").datagrid({
           fit:"true",
           pagination:"true",
           url:"${pageContext.request.contextPath}/Guru/selectAllGur.do",
           columns:[[
               {field:'albumId',checkbox:"true"},
               {field:'albumImage',title:'上师头像',width:100,formatter: function(value,row,index){
                   return "<img style='width:32px;height:32px;' border='1' src='${pageContext.request.contextPath}"+row.guruImage+"'/>";
                   }
               },
               {field:'guruName',title:'上师姓名',width:100},
               {field:'guruNickname',title:'上师法号',width:100},

               {field:'guruStatus',title:'是否冻结',width:100,
                    formatter: function(value,row,index){
                        if (row.guruStatus==0){
                            return "未冻结";
                        } else {
                            return "已冻结";
                        }
                    }
                 },
           ]],
           toolbar: [{
               /*添加工具  */
               text: "添加",
               iconCls: 'icon-add',
               handler: function () {
                   /*打开添加对话框  */
                   $("#addGuruDialog").panel('open');
               },
               /*添加工具-----------end  */
           },{
               iconCls: 'icon-help',
               text:'冻结选中',
               handler: function() {
                   $.messager.confirm("确认框", "您确认想要删除记录吗？", function (r) {
                       if (r) {
                           /*获取选中的行对象  */
                           var hang = $("#allGuru").datagrid("getSelections");
                           var ids = new Array();
                           for (var i = 0; i < hang.length; i++) {
                               ids[i] = hang[i].guruId;
                           }
                           /*重新发送ajax请求删除选中的id集合  */
                           $.ajax({
                               url: "${pageContext.request.contextPath}/Guru/delateGuru.do",
                               data: {"ids": ids},
                               type: "post",
                               /*提示ajax不做深度解析  */
                               traditional: true,
                               success: function (data) {
                                   if (data.isok) {
                                       $.messager.alert("消息", "删除成功");
                                       $("#allGuru").datagrid("reload");

                                   } else {
                                       $.messager.alert("消息", "删除失败");
                                       $("#allGuru").datagrid("reload");
                                   }
                               }
                           });
                       }
                   });
               }
           }],
          onDblClickRow: function (index, rowDate) {
              $("#updateGuruDialog").panel('open');

              $("#gurnId").val(rowDate.guruId);
              $("#guruImage").val(rowDate.guruImage);
              $("#guruImageEcho2").prop("src","${pageContext.request.contextPath}"+rowDate.guruImage);
              $("#guruName").val(rowDate.guruName);
              $("#guruNickname").val(rowDate.guruNickname);
              if(rowDate.guruStatus=="0"){
                  $("#guruStatus0").prop("checked",true);
              }else {
                  $("#guruStatus1").prop("checked",true);
              }


               console.log(rowDate);
           },
       });
    });



    function doadd(){
        $("#addform").form("submit",{
            url:"${pageContext.request.contextPath}/Guru/addGuru.do",
            onSubmit: function(){
                //提交数据前需要的判断
                return true;
            },
            success:function(data){
                var data = eval('(' + data + ')');
                if(data.isok){
                    /*添加成功弹出对话框  */
                    $.messager.alert("消息","添加成功");
                    /*关闭对话框*/
                    $("#addGuruDialog").dialog('close');
                    /*刷新table  */
                    $("#allGuru").datagrid("reload");
                }else{
                    $.messager.alert("消息","添加失败");
                };
            }

        });
    }
    /*定义点击添加对话框中的登录按钮的点击事件-----------------END  */



    /*设置修改的点击事件  */
    function update(){
        $("#updateform").form("submit",{
            url:"${pageContext.request.contextPath}/Guru/updateGuru.do",
            onSubmit: function(){
                return true;
            },
            success:function(data){
                var data = eval('(' + data + ')');  // change the JSON string to javascript object
                if(data.isok){
                    $.messager.alert("消息","修改成功");
                    /*刷新table  */
                    $("#updateGuruDialog").dialog("close",true);
                    $("#allGuru").datagrid("reload");
                }else{
                    $.messager.alert("消息","修改失败");
                };
            },

        });
    }
    /*定义点击修改对话框中的点击事件-----------------END  */




</script>


<script type="text/javascript">
    var image = '';
    function selectImage1(file) {
        if (!file.files || !file.files[0]) {
            return;
        }
        var reader = new FileReader();
        reader.onload = function (evt) {
            document.getElementById('guruImageEcho').src = evt.target.result;
            image = evt.target.result;
        }
        reader.readAsDataURL(file.files[0]);
    }
</script>
<script type="text/javascript">
    var image = '';
    function selectImage2(file) {
        if (!file.files || !file.files[0]) {
            return;
        }
        var reader = new FileReader();
        reader.onload = function (evt) {
            document.getElementById('guruImageEcho2').src = evt.target.result;
            image = evt.target.result;
        }
        reader.readAsDataURL(file.files[0]);
    }
</script>



<table id="allGuru" class="easyui-datagrid" style="width:400px;height:250px">

</table>


<!--添加的对话框表  -->
<div id="addGuruDialog">
    <form id="addform" enctype="multipart/form-data" method="post">
        头像：
        <input  type="file" class="easyui-filebox" name="Image" onchange="selectImage1(this);" data-options="required:true,missingMessage:'请选择头像'"/><br/>
        <div class="lf salebd">
            <a href="#"><img id="guruImageEcho" src="images/ad20.jpg" width="100" height="100" /></a>
        </div><br/>
        上师姓名：<input  name="guruName"><br/>
        上师法号：<input  name="guruNickname"><br/>
    </form>
</div>
<!--添加的对话框表 -----------end -->


<!--修改的对话框  -->
<div id="updateGuruDialog"  enctype="multipart/form-data">
    <form id="updateform" method="post" enctype="multipart/form-data" class="easyui-form" data-options="novalidate:true" >
        <input id="gurnId" type="text" name="guruId" style="display: none">
        <input id="guruImage" type="text" name="guruImage" style="display: none">
        上师头像图片:<input id="aa" type="file" class="easyui-filebox" name="Image" onchange="selectImage2(this);" data-options="required:true,missingMessage:'请选择封面'"/><br/>
        <div class="lf salebd">
            <a href="#"><img id="guruImageEcho2" src="" width="100" height="100" /></a>
        </div><br/>
        上师姓名：<input id="guruName" name="guruName"><br/>
        上师法号：<input id="guruNickname" name="guruNickname"><br/>
        上师状态:未冻结：<input type="radio"  id="guruStatus0" name="guruStatus" value="0"><br/>
                 已冻结：<input type="radio" id="guruStatus1"name="guruStatus" value="1"><br/>
    </form>
</div>
<!--修改的对话框----------------end  -->
